home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / QD3D to QTVR / ArticleCode / Source / Panorama.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-21  |  3.6 KB  |  156 lines  |  [TEXT/MPCC]

  1. #include "QD3DtoQTVR.h"
  2. #include "extern.h"
  3. #include "camera.h"
  4. #include "draw.h"
  5. #include "Panorama.h"
  6. #include "file.h"
  7. #include "AEVT.h"
  8. #include "MyMovies.h"
  9. #include "document.h"
  10.  
  11. #define factor 32.0
  12.                 
  13. void    MyConvert3DMFToPano(FSSpec *myFSS)
  14. {
  15.     DocumentPtr    theDocument;
  16.     
  17.     // Create the document record and make the view and camera
  18.     theDocument = MyNewDocument();
  19.     if (!theDocument)
  20.         return;
  21.     
  22.     // Read the model and add it to the document record's group
  23.     if(MyOpenFile(myFSS, theDocument)) {
  24.         MyCloseDocument(theDocument);
  25.         return;
  26.     }
  27.  
  28.     // Set up the initial camera position for object rendering
  29.     MyInitPanoCamera(theDocument);
  30.     
  31.     // Draw to the screen
  32.     MyDrawOffScreen(theDocument);
  33.     MyDrawOnScreen(theDocument);
  34.     
  35.     // Assign the Codec type
  36.     theDocument->theCodecType = kMyCodec;
  37.     
  38.     // generate the pano image
  39.     MyGeneratePanoDirect(theDocument);
  40.     
  41.     // Clean up
  42.     MyCloseDocument(theDocument);
  43. }
  44.  
  45. void    MyGeneratePanoDirect(DocumentPtr    theDocument)
  46. {
  47.     PicHandle            thePict;
  48.     float                zAngle;
  49.     long                counter = 0;
  50.     Str255                fName = "\p.pan";
  51.     short                i;
  52.     GWorldPtr            gw,largeGW;
  53.     GDHandle            gd;
  54.     FSSpec                outSpec;
  55.     Rect                sourceRect,destRect,largeRect = {0, 0, 768, 2496};
  56.     OSErr                err;
  57.     
  58.     GetGWorld(&gw, &gd);
  59.     SetGWorld(theDocument->theWindow,nil);
  60.     
  61.     // Create filename for image
  62.     outSpec = theDocument->theFileSpec;
  63.     for(i = 1; i <= fName[0];i++)
  64.         outSpec.name[i+outSpec.name[0]] = fName[i];
  65.     outSpec.name[0] += fName[0];
  66.     
  67.     // Set up buffers and regions
  68.     err = NewGWorld(&largeGW, 32, &largeRect, nil, nil, useTempMem );
  69.     if(err)
  70.         return ;
  71.     LockPixels(largeGW->portPixMap);
  72.     SetGWorld(largeGW,nil);
  73.     EraseRect( &largeRect);
  74.     sourceRect = destRect = largeRect;
  75.     sourceRect.left = 256-factor/2.0;
  76.     sourceRect.right = sourceRect.left + (short)factor;
  77.     destRect.left = 0;
  78.     destRect.right = (short)factor;
  79.     
  80.     counter = 0;
  81.     
  82.     for(zAngle = 360.0;zAngle >0.0; zAngle -= 360.0/(2496.0/factor)) {
  83.         if (Button())
  84.             break;
  85.         
  86.         // Rotate camera for next shot
  87.         MyRotateCameraY(theDocument, -2*kQ3Pi/(2496.0/factor));
  88.         
  89.         // Render image
  90.         SetGWorld(theDocument->theWindow,nil);    
  91.         MyDrawOffScreen(theDocument);
  92.         MyDrawOnScreen(theDocument);
  93.         
  94.         // Copy image to destination (paste in next slit)
  95.         SetGWorld(largeGW,nil);
  96.         LockPixels(theDocument->drawContextOffscreen->portPixMap);
  97.         CopyBits((BitMap*)&theDocument->drawContextOffscreen->portPixMap,
  98.                             (BitMap*)&largeGW->portPixMap,
  99.                             &sourceRect,
  100.                             &destRect,
  101.                             srcCopy,NULL);
  102.         UnlockPixels(theDocument->drawContextOffscreen->portPixMap);
  103.         destRect.left = destRect.left + (short)factor;
  104.         destRect.right = destRect.right + (short)factor;
  105.     }
  106.  
  107.     // Copy final image and save.    
  108.     SetGWorld(largeGW,nil);
  109.     thePict = OpenPicture(&largeGW->portRect);
  110.     CopyBits((BitMap*)&largeGW->portPixMap,
  111.                         (BitMap*)&largeGW->portPixMap,
  112.                         &largeGW->portRect,
  113.                         &largeGW->portRect,
  114.                         srcCopy,NULL);
  115.     ClosePicture();
  116.     UnlockPixels(largeGW->portPixMap);
  117.     DisposeGWorld(largeGW);
  118.     MySavePICT(thePict,&outSpec);
  119.     
  120.     // Clean up.
  121.     KillPicture(thePict);
  122.     SetGWorld(theDocument->theWindow,nil);
  123.     MyDrawOffScreen(theDocument);
  124.     MyDrawOnScreen(theDocument);
  125.     SetGWorld(gw,gd);
  126. }
  127.  
  128. OSErr MySavePICT(PicHandle picture, FSSpec *theSpec) 
  129. {
  130.     long    bytes;
  131.     OSErr    err;
  132.     short    fRefNum;
  133.     
  134.     FSpDelete (theSpec);
  135.     err = FSpCreate (theSpec, '3DVR', 'PICT', smCurrentScript);
  136.     
  137.     if(err)
  138.         return err;
  139.     
  140.     err = FSpOpenDF (theSpec, fsRdWrPerm, &fRefNum);
  141.     if(err)
  142.         return err;
  143.     
  144.     bytes = 512;
  145.     FSWrite(fRefNum,&bytes,(Ptr)NULL);
  146.     HLock((Handle)picture);
  147.     bytes = GetHandleSize((Handle)picture);
  148.     FSWrite(fRefNum,&bytes,(Ptr)(*picture));
  149.     HUnlock((Handle)picture);
  150.     FSClose(fRefNum);
  151.     FlushVol(theSpec->name,theSpec->vRefNum);
  152.     
  153.     return err;
  154. }
  155.  
  156.